from rest_framework import serializers
from core.models import Tag

class TagSerializer(serializers.ModelSerializer):
    """标签序列化器"""
    document_count = serializers.SerializerMethodField()

    class Meta:
        model = Tag
        fields = ['id', 'name', 'slug', 'description', 'created_at', 'updated_at', 'document_count']

    def get_document_count(self, obj):
        """获取标签下的文档数量"""
        return obj.documents.count() 